package com.devin.dao;

import com.devin.pojo.Traveller;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface TravellerMapper {

    /*如果在此处的上一级用了@Many注解，此处就代表一行数据，@many处用List接受多行的数据*/
    @Select("SELECT * FROM traveller WHERE id IN (SELECT travellerId FROM order_traveller WHERE orderId=#{orderId})")
    @Results({@Result(property = "id",column = "id",jdbcType = JdbcType.INTEGER),
            @Result(property = "name",column = "name",jdbcType = JdbcType.VARCHAR),
            @Result(property = "sex",column = "sex",jdbcType = JdbcType.VARCHAR),
            @Result(property = "phoneNum",column = "phoneNum",jdbcType = JdbcType.VARCHAR),
            @Result(property = "credentialsType",column = "credentialsType",jdbcType = JdbcType.INTEGER),
            @Result(property = "credentialsNum",column = "credentialsNum",jdbcType = JdbcType.VARCHAR),
            @Result(property = "travellerType",column = "travellerType",jdbcType = JdbcType.INTEGER)
    })
    public List<Traveller> getTravellerById(int orderId);

    @Update(" delete from order_traveller where orderid=#{orderId}")
    void delOrderAndTraveller(int orderId);

    @Update(" delete from traveller where id=#{id}")
    void delTraveller(Integer id);
}
